#ifndef KLineClacUnit_h__
#define KLineClacUnit_h__
#pragma once
#include <map>
#include <memory>
#include "KLineData.h"
#include "MonitorKLineCfg.h"
#include "HtBaseSubject.h"
#include "HtThreadPool.h"
#include "DBConnectPool.h"
#include "CalcLuaFun.h"
#include "DBConnMySQL.h"
class CKLineClacUnit
	:public CHtObserver
{
public:
	CKLineClacUnit(const MONCALCUNIT_CONFIG& cfg, std::list<unsigned int> dbID, std::string storeTB, std::string statusTB);
	virtual ~CKLineClacUnit();
	virtual void Update(unsigned int nMSG, UINT_PTR wparam, LONG_PTR lparam);

	bool InitCalc(std::weak_ptr<CHtThreadPool> pThreadPool, std::weak_ptr<CDBConnectPool> pDBPool);

	void doCalcKline(std::string strCode, std::map<std::string, CKLineData > mapKline);
	void update_mon_node();
private:
	bool checkTime(int time);
private:
	//<CODE, <SIGN_IP_PORT, KlineDataPTR >>
	std::map<std::string, std::map<std::string, CKLineData > > mMapCalcCode;
	std::map<std::string, std::map<std::string, std::pair<std::atomic<int>, std::string> > > mMapCodeStatus;
	std::mutex _codelock;


	std::map<unsigned int, unsigned int > m_mapCalcTime;
	unsigned int            mCalcId;
	std::list<unsigned int> nDbID;
	std::string strStoreTB;
	std::string strStatusTB;
	std::string strSign;
	unsigned int nInterval;

	CHtTimerInterface m_timer;
	std::shared_ptr<CHtThreadPool>  m_tPool;
	std::shared_ptr<CDBConnectPool> m_DBPool;
	CCalcLuaFun calcfun;
	std::mutex _calcMutex;


	int nCurDate;

};

#endif // KLineClacUnit_h__
